package com.example.chessapp;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class Rate2Activity extends AppCompatActivity {
    public static final String  TAG = "r2";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rate2);
        TextView country = findViewById(R.id.country);
        TextView rate2= findViewById(R.id.rate_2);
        TextView input_rmb = findViewById(R.id.input_rmb);
        TextView output_wb = findViewById(R.id.output_wb);

        rate2.setFocusable(false);

        Intent intent = getIntent();
        String country_str = intent.getStringExtra("titleStr");
        String rate2_str = intent.getStringExtra("detailStr");

        country.setText(country_str);
        rate2.setText(rate2_str);

        input_rmb.addTextChangedListener(new TextWatcher() {
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            public void afterTextChanged(Editable s) {

            // TODO Auto-generated method stub

            if(s.length()<=0){//判断s是否为空
                Toast.makeText(getApplicationContext(),"请输入人名币金额！", Toast.LENGTH_SHORT).show();
            }else{
            String input_rmb_str = input_rmb.getText().toString();
            float input_rmb_f = Float.parseFloat(input_rmb_str);
            float output_wb_f = input_rmb_f*Float.parseFloat(intent.getStringExtra("detailStr"));
            String output_wb_str = String.valueOf(output_wb_f);
            output_wb.setText(output_wb_str);
            }
            }
        });
    }

    public void rate_2(View v){
        Toast.makeText(getApplicationContext(),"汇率只支持自动获取，禁止手动输入！", Toast.LENGTH_SHORT).show();
    }
}